package com.huawei.cloud.phone.management.adapter.connection;

import com.huawei.cloud.phone.management.domain.connection.ConnectionGateway;
import com.huawei.cloud.phone.management.domain.connection.ConnectionStatus;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@AllArgsConstructor
@Slf4j
@Component
public class ConnectionStatusSync {
    private final ConnectionGateway connectionGateway;

    /**
     * 维护云手机连接状态，主要针对于心跳超时未上报等异常场景
     */
    @Scheduled(fixedDelay = 10 * 1000)
    public void syncStatus() {
        log.info("sync connection status.");
        int abnormalNumber = connectionGateway.maintainStatus(ConnectionStatus.CONNECTED, ConnectionStatus.UNKNOWN);
        if (abnormalNumber != 0) {
            log.warn("abnormal status number {}", abnormalNumber);
        }
    }
}
